"""
Created on 27-Oct-2009

@author: dexen
"""

import rpyc

from dexen.system import util
from dexen.system.base import task, service


class DexenSpec(object):
    def __init__(self, name):
        self.name = name
        self.tasks = {}
        self.init_task = None
        self.schema_name = ""
        self.schema_zip = None 
        self.max_num_births = None
        
        self.masterdir = None
        self.mastername = None
        self.slavedir = None
        self.objs = {}        

    def get_task_obj(self, name):
        try:
            task = self.tasks[name]
            if name in self.objs.keys():
                return self.objs[name]
            obj = task.get_obj()
            obj.__initialize__()
            self.objs[name] = obj
        except:
            import traceback
            traceback.print_exc()
        return obj
        
    def register_task(self, name, taskclass, inputsize):
        t = task.create_Task(name, taskclass, inputsize)
        self.tasks[t.name] = t
    
    def register_init(self, taskclass, outputsize=None):
        self.init_task = task.create_InitTask(taskclass, outputsize)
    
    def set_schema(self, schema_name, schema_dir):
        self.schema_zip = util.get_schema_zip(schema_dir)
        self.schema_name = schema_name
        print "DexenSpec->set_schema(), the len of zip", len(self.schema_zip)
    
    def set_max_num_births(self, num):
        self.max_num_births = num

    
        